package com.ymttest.business.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.http.client.ClientProtocolException;

import com.ymatou.iapi.couponactivity.parameter.NewUserMobileBoundBean;
import com.ymatou.iapi.couponactivity.parameter.ReceiveCouponBean;
import com.ymatou.iapi.couponactivity.service.NewUserMobileBoundCall;
import com.ymatou.iapi.couponactivity.service.ReceiveCouponCall;
import com.ymatou.promotion.api.parameter.CouponBatchBean;
import com.ymatou.promotion.api.parameter.CouponValueInfoBean;
import com.ymatou.promotion.api.parameter.CreateSellerCouponBean;
import com.ymatou.promotion.api.service.CreateSellerCouponCall;
import com.ymt.core.tool.Logger;
import com.ymttest.database.model.YmtCouponActivity;
import com.ymttest.database.model.YmtCouponActivityBatch;
import com.ymttest.database.model.YmtCouponBatch;
import com.ymttest.database.model.YmtCouponSetting;
import com.ymttest.database.sqlwapper.YmtCouponActivityWapper;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

public class CouponActivityService {

	/**
	 * 设置默认新用户手机绑定Bean
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public NewUserMobileBoundBean setNewUserMobileBoundBean() throws InterruptedException {
		Logger.comment("设置新用户手机绑定用例的默认NewUserMobileBoundBean");

		NewUserMobileBoundBean newusermobileboundBean = new NewUserMobileBoundBean();

		//YmtCouponActivity activity = new YmtCouponActivityWapper().selectTop1NewUserCouponActivity().get(0);
		YmtCouponActivity activity = new YmtCouponActivityWapper().selectCouponActivityByActivityChannel("common").get(0);
		String mobilePhone = TestDataManager.getRandomNum(11);

		newusermobileboundBean.setMobilePhone(mobilePhone);
		newusermobileboundBean.setActivityChannel(activity.getActivityChannel());

		return newusermobileboundBean;
	}

	/**
	 * 调用新用户手机绑定请求
	 * 
	 * @param newUserMobileBoundBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public NewUserMobileBoundCall NewUserMobileBound(NewUserMobileBoundBean newUserMobileBoundBean)
			throws ClientProtocolException, IOException {
		Logger.comment("根据传入bean调用新用户手机绑定请求");
		
		NewUserMobileBoundCall newusermobileboundCall = new NewUserMobileBoundCall();

		newusermobileboundCall.setData(newUserMobileBoundBean);
		newusermobileboundCall.callService();

		return newusermobileboundCall;
	}

	
	/**
	 * 设置默认领取优惠券Bean
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public ReceiveCouponBean setReceiveCouponBean() throws InterruptedException {
		Logger.comment("设置领取优惠券的默认NewUserMobileBoundBean");

		ReceiveCouponBean receivecouponBean = new ReceiveCouponBean();

		YmtCouponActivity activity = new YmtCouponActivityWapper().selectCouponActivityByActivityChannel("common").get(0);

		String mobilePhone = TestDataManager.getRandomNum(11);	
		String deviceNumber = "Dev"+TestDataManager.getRandomNum(11);	
		int userId = 30000000+Integer.parseInt(TestDataManager.getRandomNum(7));

		receivecouponBean.setActivityCode(activity.getActivityCode());
		receivecouponBean.setUserId(userId);
		receivecouponBean.setMobile(mobilePhone);
		receivecouponBean.setDeviceId(deviceNumber);

		return receivecouponBean;
	}

	/**
	 * 领取优惠券请求
	 * 
	 * @param newUserMobileBoundBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public ReceiveCouponCall ReceiveCoupon(ReceiveCouponBean receiveCouponBean)
			throws ClientProtocolException, IOException {
		Logger.comment("根据传入bean调用领取优惠券请求");
		
		ReceiveCouponCall receivecouponCall = new ReceiveCouponCall();
		receivecouponCall.setData(receiveCouponBean);
		receivecouponCall.callService();
		
		return receivecouponCall;
	}
}
